package H02.h1;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;


@WebServlet("/s01")
public class Servlet01_jdbc extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //设置响应内容和编码格式
        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        //获取当前时间
        Date date=new Date();
        //设置日期时间格式
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        String format=dateFormat.format(date);
        //输出html页面
        response.getWriter().println("<html><body>");
        response.getWriter().println("<h1>当前时间</h1>");
        response.getWriter().println("<p>"+format+"</p>");
        response.getWriter().println("</body></html>");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        super.doPost(request, response);
    }
}
